<?php

namespace App\Http\Controllers\home\lilin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;


class codeController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $data = $request->all();

        $data_r = [];
        $res = \DB::table('user')->where('u_phone',$data['phone'])
                        ->where('code',$data['code'])
                        ->first();



             if($res){
                $username = $res['u_name'];
                $phone = $res['u_phone'];

                if($username){
                    $data_r[0]=1;
                    $data_r[1]=$username;
                    
                    session(['user'=>$username]);
                    session(['user_id'=>$res['id']]);
                }else{

                    $data_r[0]=1;
                    $data_r[1]=$phone;

                    session(['user'=>$phone]);
                    session(['user_id'=>$res['id']]);
                }
                // session(['user'=>$data_r[1]]);
                // return $data_r;

             }else{

                $data_r[0]=0;
                $data_r[1]=1;

                
             }

                
             return $data_r;  
                   

        
    }

    
}
